package com.wn.main.ui.home.viewmodel

import androidx.lifecycle.viewModelScope
import com.wn.common.db.entity.VideoInfo
import com.wn.common.model.Banner
import com.wn.common.model.ProjectTabItem
import com.wn.common.model.SubProjectList
import com.wn.main.ui.home.repository.HomeRepository
import com.wn.network.viewmodel.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.StateFlow
import javax.inject.Inject

/**
 * @Author: wn
 * @Date: 2024/9/14 17:13
 * @Description: 首页 ViewModel
 */
@HiltViewModel
class HomeViewModel @Inject constructor(private val repository: HomeRepository) : BaseViewModel() {
  /**
   * 获取首页轮播图
   */
  fun getHomeBanner(): StateFlow<MutableList<Banner>?> = callBaseRequest(repository.getHomeBanner)

  /**
   * 获取首页 TabLayout 数据
   */
  fun getHomeTabs(): StateFlow<MutableList<ProjectTabItem>?> =
    callBaseRequest(repository.getHomeTabs)

  /**
   * 获取 首页视频列表
   * showLoading = true
   */
  fun getVideoList(): StateFlow<MutableList<VideoInfo>?> =
    callBaseRequest(repository.getVideoList, true)

  /**
   * 获取项目列表数据
   * 因为需要额外传递参数 不使用 BaseViewModel
   * @param page Int -- 页码
   * @param cid Int  -- id
   */
  fun getProjectList(page: Int, cid: Int): StateFlow<SubProjectList?> =
    repository.getProjectList(page, cid, viewModelScope)

}